package com.flying.client.network;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class SystemNetwork {
	
	public enum NetworkType
	{
		NoNetwork,
		Wifi,
		CMWAP,
		CMNET
	};
	
	
	public static NetworkType getCurrentSystemNetwork(Context context)
	{
		ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = cm.getActiveNetworkInfo();
		
		if (networkInfo == null)
			return NetworkType.NoNetwork;
		
		NetworkType typeResult = NetworkType.NoNetwork;
		
		int nType = networkInfo.getType();
		 
		if (nType == ConnectivityManager.TYPE_MOBILE)
		{
			if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet"))
			{
				typeResult = NetworkType.CMNET;
			}
			else
			{
				typeResult = NetworkType.CMWAP;
			}
		}
		else if (nType == ConnectivityManager.TYPE_WIFI)
		{
			typeResult = NetworkType.Wifi;
		}
		
		return typeResult;
	}
}
